package com.jz.community.moduleshoppingguide.home.presenter;

import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.home.bean.ChunnelCategoriesBean;
import com.jz.community.moduleshoppingguide.home.model.ShoppingGuideModel;
import com.jz.community.moduleshoppingguide.home.model.ShoppingModelGuideImpl;
import com.jz.community.moduleshoppingguide.home.ui.HomeView;

import java.util.List;

/**
 * Created by Tony.Fan on 2018/3/13 10:42
 */
public class HomePresenter extends BaseLifeCyclePresent<HomeView.View> implements HomeView.Presenter {

    private ShoppingGuideModel shoppingModel;
    private HomeView.View mView;

    public HomePresenter(HomeView.View v) {
        mView = v;
        shoppingModel = new ShoppingModelGuideImpl(v.getContext());
    }

    @Override
    public void setPresenter(HomeView.View v) {
        super.setPresenter(v);
    }

    @Override
    public void getChunnelCategories(String cityCode) {
        shoppingModel.getChunnelCategoriesHome(cityCode, new OnLoadListener<List<ChunnelCategoriesBean>>() {
            @Override
            public void onSuccess(List<ChunnelCategoriesBean> list) {
                mView.showChannel(list);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showError(s, 0);
            }
        });
    }

    @Override
    public void unreadCount(String type) {
        shoppingModel.unreadCount(type, new OnLoadListener<Integer>() {
            @Override
            public void onSuccess(Integer integer) {
                mView.showCount(integer);
            }

            @Override
            public void onFail(String msg, int code) {
                mView.showError(msg, 1);
            }
        });
    }
}
